<?php 
    if(isset($_POST['user'])){
        if(User::changePassword($_POST['user']['old_password'], $_POST['user']['password']) != "Successful"){
            $_POST['commit'] = "Fail";
        }else{
            $_POST['commit'] = "Success";
        }
    }
?>
<script>
    function validate(){
        var submit = true;
        var user_password = document.forms[1].user_password;
        if(user_password.value === ""){
            user_password.previousSibling.previousSibling.style.color = 'red';
            submit = false;
        }else if(user_password.value.length < 6){
                user_password.previousSibling.previousSibling.style.color = 'red';
                submit = false;
                }else
                    user_password.previousSibling.previousSibling.style.color = 'black';
        if(submit){
            document.getElementById('errorExplanation').style.diplay = "none";
            document.forms[1].submit();
        }
    }
</script>
<div id="main">
  <ul class="tabs">
  <li><a href="<?php echo $this->baseUrl; ?>Account">Profile</a></li>
  <li class="active"><a href="<?php echo $this->baseUrl; ?>Account/Password">Password</a></li>
  <li><a href="<?php echo $this->baseUrl; ?>Account/Notifications">Notifications</a></li>
</ul>
  <div class="session-form alt">
    <form onsubmit="return false;" accept-charset="UTF-8" action="<?php echo $this->baseUrl; ?>Account/Password" class="gen-form" id="edit_user_456944" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓"><input name="_method" type="hidden" value="put"><input name="authenticity_token" type="hidden" value="bjuKb3Hr9CP2vxqB0cCYIPd6FNbvLn7tRT1zjxK+UJM="></div>      
        <div class="errorExplanation" id="errorExplanation" style="<?php if($_POST['user'] && $_POST['commit'] != "Success") echo "display: inherit;"; else echo "display: none;";?>"><h2>Clank!</h2><ul><li>Old password is incorrect</li></ul></div>
        <div class="notice success" style="<?php if($_POST['user'] && $_POST['commit'] == "Success") echo "display: inherit;"; else echo "display: none;";?>">
            <h2 style="width: 700px;">Password updated</h2>
        </div>
    <fieldset>
        <label for="old_password">Old Password</label>
        <input id="user_old_password" name="user[old_password]" size="30" type="password">
      </fieldset>

      <fieldset>
        <label for="password">New Password</label>
        <input id="user_password" name="user[password]" size="30" type="password">
        <p class="message">Minimum 6 characters</p>
      </fieldset>

      <div class="form-btns">
        <input class="form-sub" name="commit" type="submit" value="Change" onclick="validate();">
      </div>
</form>  </div>
</div>